package org.opens.controller;

import org.opens.dao.ProductDao;
import org.opens.entity.Product;
import org.opens.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/api/product")
public class ProductController {

    private final Logger log = LoggerFactory.getLogger(ProductController.class);

    @Autowired
    private ProductService productService;

    @GetMapping(value = "/{id}")
    public Product findById(
            @PathVariable(value = "id") Integer id
    ) {
        log.info("查询商品信息");
        return productService.findById(id);
    }

    @GetMapping(value = "/val/{id}")
    public Product findByIdUseCustomPredicate(
            @PathVariable(value = "id") Integer id
    ) {
        log.info("查询商品信息-经过自定义路由器");
        return productService.findById(id);
    }

    @GetMapping(value = "/api1/demo1")
    public String api1Test() {
        return "api1-test";
    }

    @GetMapping(value = "/api2/demo1")
    public String api2Test() {
        return "api2-test";
    }

}
